%2 is an easy way of testing if a number is odd or even.
def modulo2(num):
result = num % 2
return result == 0
| Function Call | Return Value | |||
|---|---|---|---|---|
| modulo2(9) | → | |||
| modulo2(13) | → | |||
| modulo2(10) | → | |||
| modulo2(31) | → | |||
| modulo2(8) | → | |||
Experiment with this code on Gitpod.io